package counsel;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import contract.ContractDAO;
import contract.ContractDTO;

public class CounselUpdate extends HttpServlet{

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		req.setCharacterEncoding("utf-8");
		
		String cs_no = req.getParameter("cs_no");					//상담 번호
		String pd_no = req.getParameter("pd_no");					//상품 번호
		String pd_pback = req.getParameter("pd_pback");				//납입 구분코드
		String pd_rate = req.getParameter("pd_rate");				//금리
		String pd_prd = req.getParameter("pd_prd");					//상환 기간
		String cs_loan = req.getParameter("cs_loan");				//대출 신청액
		String cs_content = req.getParameter("cs_content");			//상담내용
		String md_pp = (String)req.getSession().getAttribute("mid");//수정자
		String ct_ing = req.getParameter("ct_ing");
		int flag = 0;
		CounselDTO coun = new CounselDTO(cs_no, pd_no, cs_loan, cs_content, pd_pback, pd_rate, pd_prd, md_pp);
		CounselDAO counDAO = new CounselDAO();
		counDAO.setCoun(coun);
		flag = counDAO.update();
		
		ContractDAO contDAO = new ContractDAO();
		ContractDTO cont = new ContractDTO();
		cont.setCs_no(cs_no);
		contDAO.setCont(cont);
		String ct_no = contDAO.returnCTNO();
		
		cont = new ContractDTO(ct_no, pd_pback, pd_rate, cs_loan, pd_prd, md_pp, ct_ing);
		contDAO.setCont(cont);
		flag = contDAO.update();
		
		req.setAttribute("Page", "UP");
		req.setAttribute("Flag", flag);
		
		//resp.sendRedirect(req.getContextPath()+"/Coun/CounList.clamp");
		//resp.sendRedirect(req.getContextPath()+"/intranet/main/invalidate.jsp?url="+req.getContextPath()+"/Coun/CounList.clamp");
		req.getRequestDispatcher("/intranet/counsel/message.jsp").forward(req, resp);
	}
	
}
